//
//  AppDelegate.swift
//  weibo
//
//  Created by 邵帅 on 16/6/23.
//  Copyright © 2016年 groupNineObject. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        
        self.window?.makeKeyAndVisible()
        
        // 判断是否登录，来显示不同界面
        self.window?.rootViewController = SSOauthModel.shareInstance.isLogin ? SSWelcomeViewController() : SSTabBarController()
        
        // 注册通知
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.enter(_:)), name: kNotificationChanged, object: nil)
        
        
        setupAppreance()
        
//        SSDBManager.shareInstance
        
        
        return true
    }
    
    // 通知的监听方法
    @objc private func enter(noti: NSNotification){
        
        if let vc = noti.object as? UIViewController {
            
            if vc is SSOauthViewController {
                
                window?.rootViewController = SSWelcomeViewController()
            }else {
                
                window?.rootViewController = SSTabBarController()
                
            }
      
        }
        
    }
    
    // 移除通知
    deinit {
        
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    

    private func setupAppreance(){
        
        // 设置 UINavigationBar 或者 UITabBar的颜色的时候,建议在程序已启动的时候就设置
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
        
        // 设置 tabBar的 tintColor
        UITabBar.appearance().tintColor = UIColor.orangeColor()
    }

}

